package com.cysd.ewmxns.ui.activity

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.cszy.ewmxns.base.BaseVMActivity
import com.cszy.ewmxns.common.AppConstants
import com.cszy.ewmxns.ext.launch

import com.cysd.ewmxns.utils.ClipboardUtils
import com.cysd.ewmxns.utils.SpUtils
import com.cysd.ewmxns.viewmodel.MainViewModel
import com.hlyj.http.base.tool.lib_hlyj_base.utils.BaseAppConstans
import qrrspeeelild.rqrc0ode.andro0ild.databinding.ActivityWifiResultBinding


class WifiResultActivity : BaseVMActivity<MainViewModel, ActivityWifiResultBinding>() {
    var appProcess :String?=null
    override fun initView(savedInstanceState: Bundle?) {
       mBinding.headTitle.headCenterTitle.text="WIFI结果"

    }

    override fun initData() {
        val scanResult = intent.getStringExtra("scanResult")
        appProcess=SpUtils.getInstance().getString(BaseAppConstans.APP_PROCESS)
        if (appProcess=="0"){
            mBinding.btnConnection.text="复制密码"
        }else{
            mBinding.btnConnection.text="连接网络"
        }

        // 提取 SSID（WiFi 名称）
        val ssid = scanResult?.substringAfter("S:")?.substringBefore(";")
        // 提取加密类型
         val encryptionType = scanResult?.substringAfter("T:")?.substringBefore(";")
       // 提取密码
         val password = scanResult?.substringAfter("P:")?.substringBefore(";")

        mBinding.tvWifiname.text=ssid
        mBinding.tvWifiJiamiType.text=encryptionType
        mBinding.tvWifipassword.text=password
    }

    override fun initListener() {
       mBinding.headTitle.headBack.setOnClickListener {
           finish()
       }

       mBinding.btnConnection.setOnClickListener {
           if (appProcess=="0"){
               //复制密码
              ClipboardUtils.copyTextFromTextView(this,mBinding.tvWifipassword,true)
           }else{
               //进入连接界面
               launch(WifiConnctionProgressActivity::class.java)
           }
       }
    }

}